<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            width: 150px;
            height: 20px;
            margin: 300px auto;
            /* border: 1px solid; */
        }

        button {
            width: 60px;
            height: 20px;
            display: block;
            float: left;
        }

        span {
            width: 30px;
            height: 20px;
            display: block;
            float: left;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app">
        <button @click="addNum">+</button>
        <span v-text>{{nums}}</span>
        <button @click="reduceNum">-</button>
    </div>
    <script src="./vue.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                nums: 0
            },
            methods: {
                addNum: function () {
                    if (this.nums >= 10) {
                        alert('不能在大啦');
                        return;
                    }
                    this.nums++;
                },
                reduceNum: function () {
                    if (this.nums <= 0) {
                        alert('不能在小啦');
                        return;
                    }
                    this.nums--;
                }
            }
        });
    </script>
</body>

</html>